//
//  CLMacro.h
//  Charles
//
//  Created by Charles on 2017/2/7.
//  Copyright © 2017年 charles. All rights reserved.
//

#ifndef CLMacro_h
#define CLMacro_h

// 懒加载
#define CL_LAZY(object, assignment) (object = object ?: assignment)

// 返回一个字符串
#define stringify   __STRING

// 设置颜色
#define CLSetColor(r, g, b) [UIColor colorWithRed:(r)/255.0f green:(g)/255.0f blue:(b)/255.0f alpha:1.0f]
//设置带透明的颜色
#define CLSetAlphaColor(r, g, b, a) [UIColor colorWithRed:(r)/255.0f green:(g)/255.0f blue:(b)/255.0f alpha:(a)]

// 设置字体
#define CLSetFont(fontName,font)    [UIFont fontWithName:(fontName) size:(font)]

// 获取屏幕宽度，高度
#define SCREEN_WIDTH ([UIScreen mainScreen].bounds.size.width)
#define SCREEN_HEIGHT ([UIScreen mainScreen].bounds.size.height)
#define MainScreenRect [UIScreen mainScreen].bounds

#define CLAPPDelegate (HTAppDelegate*)[UIApplication sharedApplication].delegate

// debug下打印，release下不打印
#ifndef __OPTIMIZE__
#define NSLog(...) NSLog(__VA_ARGS__)
#else
#define NSLog(...) {}
#endif


#define EMOJI_CODE_TO_SYMBOL(x) ((((0x808080F0 | (x & 0x3F000) >> 4) | (x & 0xFC0) << 10) | (x & 0x1C0000) << 18) | (x & 0x3F) << 24);

#define EMOJI_CODE_TO_SYMBOL(x) ((((0x808080F0 | (x & 0x3F000) >> 4) | (x & 0xFC0) << 10) | (x & 0x1C0000) << 18) | (x & 0x3F) << 24);

//存储
#define kCLSetNSUserDefaultsValue(key,value) {[[NSUserDefaults standardUserDefaults]setObject:value forKey:key];[[NSUserDefaults standardUserDefaults]synchronize];}
#define kCLGetNSUserDefaultsValue(key) [[NSUserDefaults standardUserDefaults]objectForKey:key]


/* 属性区域 */
#define kPBOOL(name)            @property (nonatomic) BOOL (name)
#define kPNSInetger(name)       @property (nonatomic) NSInteger (name)
#define kPDouble(name)          @property (nonatomic) double (name)
#define kPNSNumber(name)        @property (nonatomic, strong)NSNumber * (name)
#define kPNSString(name)        @property (nonatomic, strong)NSString * (name)
#define kPNSMutableArray(name)  @property (nonatomic, strong)NSMutableArray * (name)
#define kPNSArray(name)         @property (nonatomic, strong)NSArray * (name)
#define kPNSDate(name)          @property (nonatomic, strong)NSDate * (name)


/* GCD */
#define kDISPATCH_ASYNC_BLOCK(block) dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT,0),block)

#define kDISPATCH_MAIN_BLOCK(block) dispatch_async(dispatch_get_main_queue(),block)

/*弱引用宏*/
#define WEAKSELF(weakSelf)  __weak __typeof(&*self)weakSelf = self;


/*
 *宏定义一个单例
 *使用方法：在单例类的.h文件引用SINGLETON_AB_INTERFACE（XXXClass);
 *.m文件中引用SINGLETON_AB_IMPLEMENT(XXXClass);即可。此后可以引用该单例
 *[XXXClass sharedInstance];
 */
//接口部分
#undef  SINGLETON_CL_INTERFACE
#define SINGLETON_CL_INTERFACE( ... ) \
- (instancetype)sharedInstance; \
+ (instancetype)sharedInstance;

#undef  SINGLETON_CL_IMPLEMENT
#define SINGLETON_CL_IMPLEMENT( ... ) \
- (instancetype)sharedInstance \
{ \
return [[self class] sharedInstance]; \
} \
+ (instancetype)sharedInstance \
{ \
static dispatch_once_t once; \
static id __singleton__; \
dispatch_once( &once, ^{ __singleton__ = [[self alloc] init]; } ); \
return __singleton__; \
}

#endif /* CLMacro_h */
